-- 墨客工具箱

---@class Inker_Utility
local Inker_Utility = require 'packages/inker/pkg/util/_base'

--- 判断一名角色是否为同族成员
---@param player Player @ 自己
---@param target Player @ 待判断的角色
---@return boolean|string[] @ 如果有确定的家族，返回家族字符串表[]；对于自己必定返回true。否则返回false
Inker_Utility.FamilyMember = function(player, target)
  if target == player then
    return true
  end
  local family = {}
  local familyMap = {
    ["inker__xieliang_guan"] = { "guanyu", "guanping", "guanxing", "guansuo", "guannings", "guanyinping", "guanyue" },
    ["inker__langya_zhuge"] = { "zhugeliang", "zhugejin", "zhugedan", "zhugejun", "zhugeke", "zhugezhan", "zhugeguo", "zhugejing" }
  }
  for f, members in pairs(familyMap) do
    if table.contains(members, Fk.generals[player.general].trueName) then
      table.insertIfNeed(family, f)
    end
    if table.contains(table.map(members, function (name)
      return "god"..name
    end), Fk.generals[player.general].trueName) then
      table.insertIfNeed(family, f)
    end
    if player.deputyGeneral ~= "" then
      if table.contains(members, Fk.generals[player.deputyGeneral].trueName) then
        table.insertIfNeed(family, f)
      end
      if table.contains(table.map(members, function (name)
        return "god"..name
      end), Fk.generals[player.deputyGeneral].trueName) then
        table.insertIfNeed(family, f)
      end
    end
  end
  if #family == 0 then return false end
  local ret = {}
  for _, f in ipairs(family) do
    local members = familyMap[f]
    if table.contains(members, Fk.generals[target.general].trueName) then
      table.insertIfNeed(ret, f)
    end
    if target.deputyGeneral ~= "" and table.contains(members, Fk.generals[target.deputyGeneral].trueName) then
      table.insertIfNeed(ret, f)
    end
  end
  if #ret == 0 then return false end
  return ret
end

return Inker_Utility
